\bigskip
\bigskip
{\magonebf  2.4 Real-Valued Matrices (matrix)}

An instance of the data type $matrix$ is a matrix of double variables.

\def\name{$matrix$}
\def\type{$matrix$}

\bigskip
{\bf 1. Creation}

\create M (int\ n,\ int\ m)


creates an instance $M$ of type $matrix$, $M$ is initialized to the $n \times m$
- zero matrix.


\bigskip
{\bf 2. Operations on a matrix M}

\medskip
\+\cleartabs & \hskip 2.5truecm & \hskip 5truecm &\cr
\+\op int     dim1 {}  
                           { returns $n$, the number of rows of $M$.}
\smallskip
\+\op int     dim2 {}  
                           { returns $m$, the number of cols of $M$.}
\smallskip
\+\op vector  row {int\ i}  
                           { returns the $i$-th row of $M$ (an $m$-vector).}
\+\nop                     { \precond  $0 \le i \le n-1$.}
\smallskip
\+\op vector  col {int\ i}  
                           { returns the $i$-th column of $M$ (an $n$-vector).}
\+\nop                     { \precond  $0 \le i \le m-1$.}
\smallskip
\+\op matrix  trans {}     
                           { returns  $M^T$ ($m\times n$ - matrix). }
\smallskip
\+\op double    det {}       
                           { returns the determinant of $M$.}
\+\nop                     { \precond  $M$ is quadratic.}
\smallskip
\+\op matrix  inv {}       
                           { returns the inverse matrix of $M$. }
\+\nop                     { \precond  $M$.det() $\neq$ 0.}
\smallskip
\+\op vector  solve {vector\ b}  
                           { returns vector $x$ with $M\cdot x = b$. }
\+\nop                     { \precond $M$.dim1() = $M$.dim2() = $b$.dim()}
\+\nop                     { and $M$.det() $\neq$ 0.}
\medskip
\+\opf double\&  {int\ i,\ int\ j}        
                                 {returns $M_{i,j}$.}
\+\nop                           {\precond $0\le i\le n-1$ and $0\le j\le m-1$.}

\smallskip
\+\opb matrix    +  M_1  
                                 {Addition}
\+\nop                           {\precond $M$.dim1() = $M_1$.dim1() and}
\+\nop                           { $M$.dim2() = $M_1$.dim2().}
\smallskip
\+\opb matrix    -  M_1  
                                 {Subtraktion}
\+\nop                           {\precond $M$.dim1() = $M_1$.dim1() and}
\+\nop                           { $M$.dim2() = $M_1$.dim2().}
\smallskip
\+\opb matrix    *  M_1   
                                 {Multiplication}
\+\nop                           {\precond $M$.dim2() = $M_1$.dim1().}
\smallskip
\+\opb matrix     *  r     
                                 {Multiplication with double}
\smallskip
\+\opb vector     *  v     
                                 {Multiplication with vector}
\+\nop                           {\precond $M$.dim2() = $v$.dim().}
\medskip
\+\ops ostream\&  << O       
                                 {writes matrix $M$ to the output stream $O$}
\smallskip
\+\ops istream\&  >> I       
                                 {reads matrix $M$ from the input stream $I$}

\bigskip
{\bf 3. Implementation }
\medskip
Data type $matrix$ is implemented by two-dimensional arrays of double numbers. 
Operations det, solve, and inv take time $O(n^3)$, dim1, dim2, row, and col 
take constant time, all other operations take time $O(nm)$.  
The space requirement is $O(nm)$.

